


local function get_string_body()
	-- open read body mode
	ngx.req.read_body()

	--get mem data
	local data = ngx.req.get_body_data()
	if data then
		--curl -XPOST -d hello http://localhost/req_body
		ngx.print("body in mem:")
		ngx.print('data:', data)
		ngx.print("type:", type(data))
		return
	else
		-- read from tmp file
		--curl -XPOST -T body.txt http://localhost/req_body
		local file = ngx.req.get_body_file()
		if file then
			ngx.say("body is in file:", file)
		else 
			ngx.say("no body found!")
		end
	end
end

local function get_table_body()
	-- open read body mode
	ngx.req.read_body()

	--get mem args
	local args = ngx.req.get_post_args()
	ngx.say("table args:")
	if args then
		for k,v in pairs(args) do
			ngx.say(k,":", v)
		end
		return
	else
		-- read from tmp file
		--curl -XPOST -T body.txt http://localhost/req_body
		local file = ngx.req.get_body_file()
		if file then
			ngx.say("body is in file:", file)
		else 
			ngx.say("no body found!")
		end
	end
end

get_string_body()

--get_table_body()



